import 'package:mmkv/mmkv.dart';

class MmkvUtil {
  static final MMKV _mmkv = MMKV.defaultMMKV();

  /// 保存布尔值
  static void saveBool(String key, bool value) {
    _mmkv.encodeBool(key, value);
  }

  /// 获取布尔值
  static bool? getBool(String key, {bool? defaultValue}) {
    return _mmkv.decodeBool(key);
  }

  /// 保存整型值
  static void saveInt(String key, int value) {
    _mmkv.encodeInt(key, value);
  }

  /// 获取整型值
  static int? getInt(String key, {int? defaultValue}) {
    return _mmkv.decodeInt(key);
  }

  /// 保存字符串
  static void saveString(String key, String value) {
    _mmkv.encodeString(key, value);
  }

  /// 获取字符串
  static String? getString(String key, {String? defaultValue}) {
    return _mmkv.decodeString(key) ?? defaultValue;
  }

  /// 删除指定键的数据
  static void remove(String key) {
    _mmkv.removeValue(key);
  }

  /// 清空所有数据
  static void clearAll() {
    _mmkv.clearAll();
  }

  /// 检查是否包含某个键
  static bool contains(String key) {
    return _mmkv.containsKey(key);
  }

  /// 获取所有键
  static List<String> getAllKeys() {
    return _mmkv.allKeys;
  }
}
